package com.lecture.java8.excel.dyr.c;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test0502 {
    public static void main(String[] args) {
        String dir = "D:\\study\\tmp\\0502\\";


        String result1 = dir + "1.KZ指数.xlsx";
        DemoDataListener<Model0502_1> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(result1, Model0502_1.class,dataResultListener).sheet().doRead();
        List<Model0502_1> resultList = dataResultListener.getDataList();
        Map<String,Model0502_1> map1 = new HashMap<>();
        for (Model0502_1 result : resultList) {
            String key = result.getA() + "-" + result.getB().substring(0,4);
            map1.put(key,result);
        }

        String result2 = dir + "2.SA.xlsx";
        DemoDataListener<Model0502_2> resultDataListener2 = new DemoDataListener<>();
        EasyExcel.read(result2, Model0502_2.class,resultDataListener2).sheet().doRead();
        //全要素生产率
        List<Model0502_2> resultList2 = resultDataListener2.getDataList();
        Map<String,Model0502_2> map2 = new HashMap<>();
        for (Model0502_2 result : resultList2) {
            String key = result.getA() + "-" + result.getB().substring(0,4);
            map2.put(key,result);
        }

        String result3 = dir + "3.WW.xlsx";
        DemoDataListener<Model0502_3> resultDataListener3 = new DemoDataListener<>();
        EasyExcel.read(result3, Model0502_3.class,resultDataListener3).sheet().doRead();
        //全要素生产率
        List<Model0502_3> resultList3 = resultDataListener3.getDataList();
        Map<String,Model0502_3> map3 = new HashMap<>();
        for (Model0502_3 result : resultList3) {
            String key = result.getA() + "-" + result.getB().substring(0,4);
            map3.put(key,result);
        }

        String result4 = dir + "4.【更新2021】各省互联网普及率 2011-2021(1).xlsx";
        DemoDataListener<Model0502_4> resultDataListener4 = new DemoDataListener<>();
        EasyExcel.read(result4, Model0502_4.class,resultDataListener4).sheet().doRead();
        //全要素生产率
        List<Model0502_4> resultList4 = resultDataListener4.getDataList();
        Map<String,Model0502_4> map4 = new HashMap<>();
        for (Model0502_4 result : resultList4) {
            String key = result.getA() + "-" + result.getB();
            map4.put(key,result);
        }

        String result5 = dir + "5.杭州-球面距离.xls";
        DemoDataListener<Model0502_5> resultDataListener5 = new DemoDataListener<>();
        EasyExcel.read(result5, Model0502_5.class,resultDataListener5).sheet().doRead();
        //全要素生产率
        List<Model0502_5> resultList5 = resultDataListener5.getDataList();
        Map<String,Model0502_5> map5 = new HashMap<>();
        for (Model0502_5 result : resultList5) {
            String key = result.getA();
            map5.put(key,result);
        }


        String dataResultFileName = dir + "6.显著性0.004的(2).xlsx";
        DemoDataListener<Result> dataListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Result.class,dataListener).sheet().doRead();
        List<Result> dataList = dataListener.getDataList();

        for (Result model : dataList) {
            String key = model.getA() + "-" + model.getB();
            Model0502_1 r1 = map1.get(key);
            if (r1 != null) {
                model.setAo(r1.getC());
            }

            Model0502_2 r2 = map2.get(key);
            if (r2 != null) {
                model.setAp(r2.getC());
            }

            Model0502_3 r3 = map3.get(key);
            if (r3 != null) {
                model.setAq(r3.getC());
            }
            Model0502_4 r4 = map4.get(model.getI()+"-" + model.getB());
            if (r4 != null) {
                model.setAr(r4.getC());
            }


            Model0502_5 r5 = map5.get(model.getJ());
            if (r5 != null) {
                model.setAs(r5.getB());
            }

        }

        EasyExcel.write(dir + "result2.xlsx", Result.class)
                .sheet("a").doWrite(dataList);
    }
}
